﻿#if FRAMEWORK_35

using System;
using System.Collections.Generic;
using System.Text;

using System.Xml;

using VisualEditor.Core;
using VisualEditor.Objects;


namespace VisualEditor.IO
{
    public static class AthenaReaderExtender
    {
        private static void ReadLabel(XmlElement element, IDrawable drawable)
        {
            drawable.ShowLabel = Utility.ReadBoolean(element, "showLabel");
            drawable.LabelColor = Utility.ConverARGBToColor(element.GetAttribute("labelColor"));

            drawable.LabelFont = new System.Drawing.Font(element.GetAttribute("font"), Utility.ReadSingle(element, "size"));
            drawable.LabelH = (VisualEditor.Objects.IDrawable.HorizontalAlignment)Enum.Parse
                (typeof(VisualEditor.Objects.IDrawable.HorizontalAlignment), element.GetAttribute("labelH"));
            drawable.LabelV = (VisualEditor.Objects.IDrawable.VerticalAlignment)Enum.Parse
                (typeof(VisualEditor.Objects.IDrawable.VerticalAlignment), element.GetAttribute("labelV"));
        }
        private static void ReadBoundingBox(XmlElement element, IDrawable drawable)
        {
            drawable.Location = new System.Drawing.PointF(Utility.ReadSingle(element, "x"),
                                Utility.ReadSingle(element, "y"));

            drawable.Dimensions = new System.Drawing.SizeF(
                Utility.ReadSingle(element, "width"), Utility.ReadSingle(element, "height"));
        }
        public static void ReadFromXML(this IDrawable drawable, XmlElement element)
        {
            drawable.ID = element.GetAttribute("id");
            drawable.Label = element.GetAttribute("label");

            ReadBoundingBox(element, drawable);
            
            drawable.FillColorStart = Utility.ConverARGBToColor(element.GetAttribute("startColor"));
            drawable.FillColorEnd = Utility.ConverARGBToColor(element.GetAttribute("endColor"));

            ReadLabel(element, drawable);
            
            drawable.IsVisible = Utility.ReadBoolean(element, "isVisible");
            drawable.View = (VisualEditor.Objects.IDrawable.ViewType)Enum.Parse(typeof(VisualEditor.Objects.IDrawable.ViewType), element.GetAttribute("viewType"));
        }
    }
}
#endif